package com.huang.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huang.entity.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author han
 * @since 2022-01-16 18:42:58
 */
@Mapper
public interface RoleDao extends BaseMapper<Role> {

    @Delete("<script>delete sys_menu_role where role_id = #{roleId}</script>")
    void deleteRoleAndMenu(@Param("roleId") String roleId);

    @Insert("<script>insert into sys_menu_role(id, menu_id, role_id, version, deleted, modify_date, create_date) values(#{id}, #{menuId}, #{roleId}, 0, 0, now(), now())</script>")
    void saveRoleAndMenu(@Param("id") String id, @Param("roleId") String roleId, @Param("menuId") String menuId);

    @Select("<script>select a.* from sys_role as a, sys_user_role as b where b.user_id = #{userId} and a.deleted = 0</script>")
    List<Role> findByUserId(String userId);
}
